package xworker.gluon.glisten.control;

import com.gluonhq.charm.glisten.control.FloatingActionButton;
import org.xmeta.ActionContext;
import org.xmeta.Thing;
import xworker.javafx.beans.property.PropertyFactory;
import xworker.javafx.util.JavaFXUtils;

public class FloatingActionButtonActions {
    static{
        PropertyFactory.regist(FloatingActionButton.class, "idProperty", o -> {
            FloatingActionButton obj = (FloatingActionButton) o;
            return obj.idProperty();
        });
        PropertyFactory.regist(FloatingActionButton.class, "textProperty", o -> {
            FloatingActionButton obj = (FloatingActionButton) o;
            return obj.textProperty();
        });
        PropertyFactory.regist(FloatingActionButton.class, "onActionProperty", o -> {
            FloatingActionButton obj = (FloatingActionButton) o;
            return obj.onActionProperty();
        });
    }

    public static void init(FloatingActionButton node, Thing thing, ActionContext actionContext) {
        String id = JavaFXUtils.getObject(thing, "id", actionContext);
        if (id != null) {
            node.setId(id);
        }

        String text = JavaFXUtils.getObject(thing, "text", actionContext);
        if (text != null) {
            node.setText(text);
        }

    }

    public static FloatingActionButton create(ActionContext actionContext) {
        Thing self = actionContext.getObject("self");
        FloatingActionButton node = new FloatingActionButton();
        init(node, self, actionContext);

        actionContext.peek().put("parent", node);
        for (Thing child : self.getChilds()) {
            child.doAction("create", actionContext);
        }

        actionContext.g().put(self.getMetadata().getName(), node);
        return node;
    }

}